import Cookies from 'js-cookie'

const bbt = 'bauthorization'

function setCookie(name, v){
    Cookies.set(name, v)
}

function setCookieBBT(v){
    Cookies.set(bbt, v)
}


function getCookie(name){
    return Cookies.get(name)
}

function getCookieBBT(){
    return Cookies.get(bbt)
}
function removeCookieBBT(){
    return Cookies.remove(bbt)
}

function getBBTKey(){
    return bbt;
}

function getHeaderParam(){
    const headerParam ={}
    headerParam[bbt] = Cookies.get(bbt);
    return headerParam;
}

function invokeCounter(name){
    let counter =  Cookies.get(name);
    if(counter && counter !='NaN'){
        const counter = 1 + counter;
        Cookies.set(name, counter);
    }else{
        Cookies.set(name, 1);
    }
}
function emptyCounter(name){
    console.log('清空计数器', name)
    Cookies.set(name, 0);
}
function getCounter(name){
    let counter =  Cookies.get(name);
    if(!counter || counter == 'NaN'){
        counter = 0;
    }
    return counter;
}


export {setCookie, getCookie, setCookieBBT, getCookieBBT, getBBTKey, invokeCounter, getCounter, emptyCounter, getHeaderParam, removeCookieBBT}